import Router from '../../utils/router';
import base from '../../config/base.js';
import service from '../../services/aftersale';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    icon_close: base.static + 'aftersale/afterDetail2.png',
    icon_success: base.static + 'aftersale/afterDetail4.png',
    icon_center: base.static + 'aftersale/afterDetail1.png',
    icon_tuihuozhong: base.static + 'aftersale/afterDetail3.png',
    orid: '',
    srorid: '',
    saleAfter: '',
    supplierExpess: '',
    goods: '',
    order: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      srorid: options.srorid,
      orid: options.orid,
    });
    that.getDetail();
    that.getSupplierAddr();
  },
  //填写快递单号
  goExpress: function(){
    let that = this;
    Router.go('expressnum', `srorid=${that.data.srorid}&orid=${that.data.orid}`)
  },
  // 售后详情
  getDetail: function(){
    let that = this;
    let params = {
      srorid: that.data.srorid,
    }
    service.saleAfterGetInfo(params, function (res) {
      if (res && res.code == 1) {
        that.setData({
          saleAfter: res.data.saleAfter,
          goods: res.data.goods,
          order: res.data.order,
        });
      }
      wx.stopPullDownRefresh();
    });
  },
  // 撤销申请
  cancelSub: function () {
    let that = this;
    let params = {
      srorid: that.data.srorid,
      saleafter_status: 2
    }
    wx.showModal({
      title: '提示',
      content: '确定要撤销吗',
      success: function (res) {
        if (res.confirm) {
          service.saleAfterUpdate(params, function (res) {
            if (res && res.code == 1) {
              that.getDetail();
              that.getSupplierAddr();
            }
          });
        }
      }
    })
    
  },
  // 获取供应商退货地址
  getSupplierAddr: function(){
    let that = this;
    let params = {
      id: that.data.orid,
    }
    service.getsupplieraddr(params, function (res) {
      if (res && res.code == 1) {
        that.setData({
          supplierExpess: res.data
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      saleAfter: '',
      supplierExpess: '',
      goods: '',
      order: '',
    });  
    this.getDetail();
    this.getSupplierAddr();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
})